package com.megagoodsoftware.MediaShare;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * A Flickr user, in the strictest sense, is only defined by its NSID. The NSID
 * is usually obtained by {@link Flickr#findByUserName(String)
 * looking up a user by its user name}.
 *
 * To obtain more information about a given user, refer to the UserInfo class.
 *
 * @see Flickr#findByUserName(String)
 * @see Flickr#getUserInfo(com.google.android.photostream.Flickr.User) 
 * @see com.google.android.photostream.Flickr.UserInfo
 */
class User implements Parcelable {
    private final String mId;
    private final String mHash;
    
    User(String id, String password) {
        mId = id;
        mHash = password;
    }

    private User(Parcel in) {
        mId = in.readString();
        mHash = in.readString();
    }

    /**
     * Returns the Flickr NSDID of the user. The NSID is used to identify the
     * user with any operation performed on Flickr.
     *
     * @return The user's NSID.
     */
    String getId() {
        return mId;
    }

    /**
     * Returns the SmugMug Hash of the user. The NSID is used to identify the
     * user with any operation performed on SmugMug.
     *
     * @return The user's Hash.
     */
    String getPassword() {
        return mHash;
    }

   /**
     * Creates a new instance of this class from the specified Flickr NSID.
     *
     * @param id The NSID of the Flickr user.
     *
     * @return An instance of User whose id might not be valid.
     */
    static User fromId(String id) {
        return new User(id, null);
    }

    @Override
    public String toString() {
        return "User[" + mId + "]";
    }

    public int describeContents() {
        return 0;
    }

    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(mId);
        dest.writeString(mHash);
    }

    public static final Parcelable.Creator<User> CREATOR = new Parcelable.Creator<User>() {
        public User createFromParcel(Parcel in) {
            return new User(in);
        }

        public User[] newArray(int size) {
            return new User[size];
        }
    };
}